package com.main.usermanagement.domain.user.valueobject;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.Data;

@Data
public class Email {
    private  String value;
    @JsonCreator
    public Email (){};

    @JsonCreator
    public Email(String value) {
        if (!value.isEmpty() && !isValid(value)) {
            throw new IllegalArgumentException("Invalid email address");
        }
        this.value = value;
    }

    private static boolean isValid(String value) {
        return  value.matches("^[\\w-.]+@([\\w-]+\\.)+[\\w-]{2,4}$");
    }

}
